//
//  YDFundDetailsTableCell.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/14.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDFundDetailsTableCell.h"
#import "YDFundDetailsModel.h"

@interface YDFundDetailsTableCell()

//交易类型
@property (nonatomic , weak) UILabel *tradeType;
//交易年月日
@property (nonatomic , weak) UILabel *yearLabel;
//交易时分秒
@property (nonatomic , weak) UILabel *hourLabel;
//盈利
@property (nonatomic , weak) UILabel *accountNumberLabel;
//分割线
@property (nonatomic , weak) UIView *lineView;
@end


@implementation YDFundDetailsTableCell


-(void)setModel:(YDFundDetailsModel *)model
{

    /*

     Recharge("1", "充值"),

     Withdrawals("2", "提现"),

     ServiceFee("3", "服务费"),

     ReserveFund("4", "冻结履约保证金"),

     DeferredCharges("5", "递延费"),

     ReturnReserveFund("6", "退回履约保证金"),

     Loss("7", "亏损"),

     Profit("8", "盈利");

     */
    _model = model;
    /*
    if ([model.type isEqualToString:@"Recharge"]) {//充值
        self.stockName.text = @"充值金额";
        self.stockCode.text = @"";
        self.tradeType.text = model.flowText;
        self.profit.text = [NSString stringWithFormat:@"+%@",model.fundAccunt];
        if ([model.amount floatValue] >=0) {
           self.profit.textColor = [UIColor colorWithHexString:paleRed];
        }else{
            self.profit.textColor = [UIColor colorWithHexString:leafyGreen];
        }

    }else if ([model.type isEqualToString:@"Withdrawals"]){//提现
        self.stockName.text = @"提现金额";
        self.stockCode.text = @"";
        self.tradeType.text = model.flowText;
        if ([model.amount floatValue] >=0) {
            self.profit.text = [NSString stringWithFormat:@"%@",model.fundAccunt];
            self.profit.textColor = [UIColor colorWithHexString:paleRed];
        }else{
            self.profit.text = [NSString stringWithFormat:@"-%@",model.fundAccunt];
            self.profit.textColor = [UIColor colorWithHexString:leafyGreen];
        }
    }else if ([model.type isEqualToString:@"ServiceFee"]){//服务费
        self.stockName.text = [NSString stringWithFormat:@"%@",model.stockName];
        self.stockCode.text = [NSString stringWithFormat:@"(%@)",model.stockCode];
        self.tradeType.text = [NSString stringWithFormat:@"%@即时买入" , model.strategyTypeName];
        self.profit.textColor = NumberColor(129, 128, 129);
        if ([model.amount floatValue] >= 0) {
            self.profit.attributedText = [NSString getAttriNeedChangeString:[NSString stringWithFormat:@"+%@",model.fundAccunt] changeColor:[UIColor colorWithHexString:paleRed] changeFont:[UIFont systemFontOfSize:font16ScreenWRate * LKScreenW] sourceString:[NSString stringWithFormat:@"%@+%@",model.flowText , model.fundAccunt]];
        }else{
            self.profit.attributedText = [NSString getAttriNeedChangeString:[NSString stringWithFormat:@"-%@",model.fundAccunt] changeColor:[UIColor colorWithHexString:leafyGreen] changeFont:[UIFont systemFontOfSize:font16ScreenWRate * LKScreenW] sourceString:[NSString stringWithFormat:@"%@-%@",model.flowText , model.fundAccunt]];
        }


    }else if ([model.type isEqualToString:@"ReserveFund"]){//冻结履约保证金
        self.stockName.text = @"冻结金额";
        self.stockCode.text = @"";
        self.tradeType.text = model.flowText;

        if ([model.amount floatValue] >=0) {
            self.profit.text = [NSString stringWithFormat:@"%@",model.fundAccunt];
            self.profit.textColor = [UIColor colorWithHexString:paleRed];
        }else{
            self.profit.text = [NSString stringWithFormat:@"-%@",model.fundAccunt];
            self.profit.textColor = [UIColor colorWithHexString:leafyGreen];
        }
    }else if ([model.type isEqualToString:@"DeferredCharges"]){//递延费
        self.stockName.text = @"递延费";
        self.stockCode.text = @"";
        self.tradeType.text = model.flowText;
        if ([model.amount floatValue] >=0) {
            self.profit.text = [NSString stringWithFormat:@"+%@",model.fundAccunt];
            self.profit.textColor = [UIColor colorWithHexString:paleRed];
        }else{
            self.profit.text = [NSString stringWithFormat:@"%@",model.fundAccunt];
            self.profit.textColor = [UIColor colorWithHexString:leafyGreen];
        }
    }else if ([model.type isEqualToString:@"ReturnReserveFund"]){//退回履约保证金
        self.stockName.text = @"解冻金额";
        self.stockCode.text = @"";
        self.tradeType.text = model.flowText;

        if ([model.amount floatValue] >=0) {
            self.profit.text = [NSString stringWithFormat:@"+%@",model.fundAccunt];
            self.profit.textColor = [UIColor colorWithHexString:paleRed];
        }else{
            self.profit.text = [NSString stringWithFormat:@"%@",model.fundAccunt];
            self.profit.textColor = [UIColor colorWithHexString:leafyGreen];
        }
    }else if ([model.type isEqualToString:@"Loss"]){//亏损  只有亏损或者盈利才显示T点买策略
        self.stockName.text = [NSString stringWithFormat:@"%@" , model.stockName];
        self.stockCode.text = [NSString stringWithFormat:@"(%@)" , model.stockCode];
        self.tradeType.text = [NSString stringWithFormat:@"%@即时卖出",model.strategyTypeName];
        if ([model.amount floatValue] >= 0) {
            self.profit.attributedText = [NSString getAttriNeedChangeString:[NSString stringWithFormat:@"+%@",model.fundAccunt] changeColor:[UIColor colorWithHexString:paleRed] changeFont:[UIFont boldSystemFontOfSize:font14ScreenWRate * LKScreenW] sourceString:[NSString stringWithFormat:@"%@+%@",model.flowText , model.fundAccunt]];
        }else{
            self.profit.attributedText = [NSString getAttriNeedChangeString:[NSString stringWithFormat:@"-%@",model.fundAccunt] changeColor:[UIColor colorWithHexString:leafyGreen] changeFont:[UIFont boldSystemFontOfSize:font14ScreenWRate * LKScreenW] sourceString:[NSString stringWithFormat:@"%@-%@",model.flowText , model.fundAccunt]];
        }
    }else if ([model.type isEqualToString:@"Profit"]){//盈利
        self.stockName.text = [NSString stringWithFormat:@"%@" , model.stockName];
        self.stockCode.text = [NSString stringWithFormat:@"(%@)" , model.stockCode];
        self.tradeType.text = [NSString stringWithFormat:@"%@即时卖出",model.strategyTypeName];
        if ([model.amount floatValue] >= 0) {
            self.profit.attributedText = [NSString getAttriNeedChangeString:[NSString stringWithFormat:@"+%@",model.fundAccunt] changeColor:[UIColor colorWithHexString:paleRed] changeFont:[UIFont boldSystemFontOfSize:font14ScreenWRate * LKScreenW] sourceString:[NSString stringWithFormat:@"%@+%@",model.flowText , model.fundAccunt]];
        }else{
            self.profit.attributedText = [NSString getAttriNeedChangeString:[NSString stringWithFormat:@"-%@",model.fundAccunt] changeColor:[UIColor colorWithHexString:leafyGreen] changeFont:[UIFont boldSystemFontOfSize:font14ScreenWRate * LKScreenW] sourceString:[NSString stringWithFormat:@"%@-%@",model.flowText , model.fundAccunt]];
        }
    }else if ([model.type isEqualToString:@"Promotion"]){//推广佣金
        self.stockName.text = model.flowText;
        self.stockCode.text = @"";
        self.tradeType.text = model.flowText;
        if ([model.amount floatValue] >= 0) {
            self.profit.attributedText = [NSString getAttriNeedChangeString:[NSString stringWithFormat:@"+%@",model.fundAccunt] changeColor:[UIColor colorWithHexString:paleRed] changeFont:[UIFont boldSystemFontOfSize:font14ScreenWRate * LKScreenW] sourceString:[NSString stringWithFormat:@"%@+%@",@"佣金" , model.fundAccunt]];
        }else{
            self.profit.attributedText = [NSString getAttriNeedChangeString:[NSString stringWithFormat:@"-%@",model.fundAccunt] changeColor:[UIColor colorWithHexString:leafyGreen] changeFont:[UIFont boldSystemFontOfSize:font14ScreenWRate * LKScreenW] sourceString:[NSString stringWithFormat:@"%@-%@",@"佣金" , model.fundAccunt]];
        }
    }
     */
    //    if (model.stockName.length) {
    //        //
    //        self.tradeType.text = [NSString stringWithFormat:@"%@ %@",model.stockName,model.flowText];
    //    }else
    //    {
    //        self.tradeType.text = model.flowText;
    //    }
    self.tradeType.text = model.flowText;
    
    //金额
    if ([model.amount floatValue] >= 0) {
        self.accountNumberLabel.text = [NSString stringWithFormat:@"%@" , model.fundAccunt];
        self.accountNumberLabel.textColor = [UIColor colorWithHexString:paleRed];
    }else{
        self.accountNumberLabel.text = [NSString stringWithFormat:@"%@" , model.fundAccunt];
        self.accountNumberLabel.textColor = [UIColor colorWithHexString:leafyGreen];
    }
    
    
    //时间
    self.yearLabel.text = model.year;
    self.hourLabel.text = model.hour;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *fundDetailsTableCell = @"YDFundDetailsTableCell";
    YDFundDetailsTableCell *cell = [tableView dequeueReusableCellWithIdentifier:fundDetailsTableCell];
    if (cell == nil) {
        cell = [[YDFundDetailsTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:fundDetailsTableCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.backgroundColor = [UIColor whiteColor];
        [self lineView];
        [self tradeType];
        [self yearLabel];
        [self hourLabel];
        [self accountNumberLabel];

    }
    return self;
}
-(UIView *)lineView
{
    if (_lineView == nil) {
        UIView *lineView = [[UIView alloc] init];
        [self addSubview:lineView];
        lineView.backgroundColor = NumberColor(247, 247, 247);
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.height.equalTo(@1);
        }];
        
        _lineView = lineView;
    }
    return _lineView;
}
-(UILabel *)tradeType
{
    if (_tradeType == nil) {
        UILabel *tradeType = [[UILabel alloc] init];
        [self.contentView addSubview:tradeType];
        tradeType.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        tradeType.textColor = NumberColor(129, 128, 129);
        tradeType.textAlignment = NSTextAlignmentLeft;
        tradeType.text = @"T+1即时卖出";
        [tradeType mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(rate375(25));
            if (isPhoneX) {
                make.bottom.equalTo(self.mas_centerY).offset(-rateX812(2));
            }else{
                make.bottom.equalTo(self.mas_centerY).offset(-rate750(2));
            }
            make.right.equalTo(self).offset(-rate375(20));
        }];
        tradeType.adjustsFontSizeToFitWidth = YES;
        _tradeType = tradeType;
    }
    return _tradeType;
}


-(UILabel *)yearLabel
{
    if (_yearLabel == nil) {
        UILabel *yearLabel = [[UILabel alloc] init];
        [self.contentView addSubview:yearLabel];
        yearLabel.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        yearLabel.textColor = NumberColor(129, 128, 129);
        yearLabel.textAlignment = NSTextAlignmentLeft;
        yearLabel.text = @"2017-12-01";
        [yearLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.tradeType);
            if (isPhoneX) {
                make.top.equalTo(self.mas_centerY).offset(rateX812(2));
            }else{
                make.top.equalTo(self.mas_centerY).offset(rate750(2));
            }
        }];
        yearLabel.adjustsFontSizeToFitWidth = YES;
        _yearLabel = yearLabel;
    }
    return _yearLabel;
}
-(UILabel *)hourLabel
{
    if (_hourLabel == nil) {
        UILabel *hourLabel = [[UILabel alloc] init];
        [self.contentView addSubview:hourLabel];
        hourLabel.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        hourLabel.textColor = NumberColor(129, 128, 129);
        hourLabel.textAlignment = NSTextAlignmentLeft;
        hourLabel.text = @"14:10:00";
        [hourLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.yearLabel.mas_right).offset(rate375(5));
            make.centerY.equalTo(self.yearLabel);
        }];
        hourLabel.adjustsFontSizeToFitWidth = YES;
        _hourLabel = hourLabel;
    }
    return _hourLabel;
}

-(UILabel *)accountNumberLabel
{
    if (_accountNumberLabel == nil) {
        UILabel *accountNumberLabel = [[UILabel alloc] init];
        [self.contentView addSubview:accountNumberLabel];
        accountNumberLabel.font = [UIFont boldSystemFontOfSize:font16ScreenWRate * LKScreenW];
        accountNumberLabel.textColor = NumberColor(129, 128, 129);
        accountNumberLabel.textAlignment = NSTextAlignmentRight;
        accountNumberLabel.text = @"+17";
        [accountNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-rate375(25));
            make.centerY.equalTo(self);
            make.left.equalTo(self.mas_centerX);
        }];
        accountNumberLabel.adjustsFontSizeToFitWidth = YES;
        _accountNumberLabel = accountNumberLabel;
    }
    return _accountNumberLabel;
}

//-(void)setFrame:(CGRect)frame
//{
//    CGFloat margin;
//    if (isPhoneX) {
//        margin = rateX812(10);
//    }else{
//        margin = rate750(10);
//    }
//    frame.size.height -= margin;
//    frame.origin.y -= margin;
//    [super setFrame:frame];
//}

@end
